//
//  SupplyAndDemandCell.m
//  phmall
//
//  Created by admin on 2017/11/15.
//  Copyright © 2017年 admin. All rights reserved.
//

#import "SupplyAndDemandCell.h"

@implementation SupplyAndDemandCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
+ (instancetype)theShareCellWithTableView:(UITableView *)tableView{
    
    static NSString *ID = @"SetCell";
    SupplyAndDemandCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[SupplyAndDemandCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
    }
    return cell;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.contentView.backgroundColor=[UIColor whiteColor];
        
        self.img=[[UIImageView alloc]init];
        self.img.image=[UIImage imageNamed:@"图片"];
        self.img.contentMode=UIViewContentModeScaleAspectFill;
        ViewBorderRadius(self.img, 5, 0, [UIColor clearColor]);
        [self.contentView addSubview:self.img];
        
        self.type=[[UILabel alloc]init];
        self.type.text=@"【供应】你猜你猜你猜猜猜你猜你猜你猜猜猜";
        self.type.numberOfLines=2;
        self.type.textColor=[UIColor orangeColor];
        self.type.font=[UIFont systemFontOfSize:15];
        [self.contentView addSubview:self.type];
        
        self.describe =[[UILabel alloc]init];
        self.describe.textColor=[UIColor colorWithHexString:@"#adadad"];
        self.describe.numberOfLines=2;
        self.describe.text=@"ROSIE FOR AUTOGRAPH ROSIE FOR AUTOGRAPH";
        self.describe.font=[UIFont systemFontOfSize:13];
        [self.contentView addSubview:self.describe];
        
        self.time =[[UILabel alloc]init];
        self.time.textColor=[UIColor colorWithHexString:@"#adadad"];
        self.time.numberOfLines=2;
        self.time.text=@"发布时间:19/10/17";
        self.time.font=[UIFont systemFontOfSize:13];
        [self.contentView addSubview:self.time];
        
        self.price=[[UILabel alloc]init];
        self.price.text=@"价格:商议";
        self.price.numberOfLines=2;
        self.price.textColor=[UIColor orangeColor];
        self.price.font=[UIFont systemFontOfSize:15];
        [self.contentView addSubview:self.price];
        
        self.check=[UIButton buttonWithType:UIButtonTypeCustom];
        [self.check setTitle:Localized(@"围观") forState:UIControlStateNormal];
        ViewBorderRadius(self.check, 5, 0, [UIColor clearColor]);
        self.check.titleLabel.font=[UIFont systemFontOfSize:13];
        self.check.backgroundColor=[UIColor orangeColor];
        [self.contentView addSubview:self.check];
    
        self.line=[[UIView alloc]init];
        self.line.backgroundColor=[UIColor groupTableViewBackgroundColor];
        [self.contentView addSubview:self.line];
    }
    return self;
}
-(void)layoutSubviews{
    [super layoutSubviews];
    CGSize superSize = self.contentView.frame.size;
    
    if (CGSizeEqualToSize(superSize, CGSizeZero)) {
        return;
    }
    
    [self.img mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.offset(10);
        make.bottom.offset(-10);
        make.width.equalTo(self.img.mas_height);
    }];
    
    [self.type mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.img.mas_right).offset(10);
        make.right.offset(-10);
        make.top.equalTo(self.img).offset(0);
    }];
    
    [self.describe mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.img.mas_right).offset(10);
        make.right.offset(-10);
        make.top.equalTo(self.type.mas_bottom).offset(5);
    }];
    
    [self.time mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.img).offset(-0);
        make.left.equalTo(self.img.mas_right).offset(10);
        make.right.equalTo(self.check.mas_left).offset(-8);
    }];

    [self.price mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.time.mas_top).offset(-4);
        make.left.equalTo(self.img.mas_right).offset(10);
    }];
    
    [self.check mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.img.mas_bottom).offset(-10);
        make.right.offset(-10);
        make.width.offset(50);
        make.height.offset(20);
    }];
    
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(0);
        make.right.offset(0);
        make.height.offset(1);
        make.top.offset(0);
    }];
}
-(void)setModel:(SupplyAndDemandModel *)model{
    _model=model;
    self.price.text=[NSString stringWithFormat:@"price:%@",model.price];
    [self.img sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",IMGURL,model.pic]] placeholderImage:[UIImage imageNamed:@"图片空白页"]];
    self.type.text=model.goods_name;
    self.describe.text=model.intro;
    self.time.text=[NSString stringWithFormat:@"release time:%@",[PublicClass timeWithTimeIntervalString:model.register_date]];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
